load("@bazel_gomock//:gomock.bzl", "gomock")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("//build:STRINGER.bzl", "stringer")
load("//pkg/testutils:buildutil/buildutil.bzl", "disallowed_imports_test")

go_library(
    name = "kvcoord",
    srcs = [
        "batch.go",
        "condensable_span_set.go",
        "dist_sender.go",
        "dist_sender_circuit_breaker.go",
        "dist_sender_mux_rangefeed.go",
        "dist_sender_rangefeed.go",
        "doc.go",
        "local_test_cluster_util.go",
        "lock_spans_over_budget_error.go",
        "range_iter.go",
        "rangefeed_message.go",
        "replica_slice.go",
        "testing_knobs.go",
        "transport.go",
        "transport_race.go",
        "transport_regular.go",
        "txn_coord_sender.go",
        "txn_coord_sender_factory.go",
        "txn_coord_sender_savepoints.go",
        "txn_interceptor_committer.go",
        "txn_interceptor_heartbeater.go",
        "txn_interceptor_metric_recorder.go",
        "txn_interceptor_pipeliner.go",
        "txn_interceptor_seq_num_allocator.go",
        "txn_interceptor_span_refresher.go",
        "txn_lock_gatekeeper.go",
        "txn_metrics.go",
        ":gen-txnstate-stringer",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/base",
        "//pkg/build",
        "//pkg/gossip",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/kvbase",
        "//pkg/kv/kvclient",
        "//pkg/kv/kvclient/rangecache",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/kv/kvserver/txnwait",
        "//pkg/multitenant",
        "//pkg/roachpb",
        "//pkg/rpc",
        "//pkg/rpc/nodedialer",
        "//pkg/server/telemetry",
        "//pkg/settings",
        "//pkg/settings/cluster",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/storage/enginepb",
        "//pkg/util",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/buildutil",
        "//pkg/util/circuit",
        "//pkg/util/ctxgroup",
        "//pkg/util/envutil",
        "//pkg/util/errorutil/unimplemented",
        "//pkg/util/future",
        "//pkg/util/grpcutil",
        "//pkg/util/hlc",
        "//pkg/util/humanizeutil",
        "//pkg/util/iterutil",
        "//pkg/util/limit",
        "//pkg/util/log",
        "//pkg/util/metamorphic",
        "//pkg/util/metric",
        "//pkg/util/pprofutil",
        "//pkg/util/quotapool",
        "//pkg/util/randutil",
        "//pkg/util/retry",
        "//pkg/util/shuffle",
        "//pkg/util/span",
        "//pkg/util/startup",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_errors//errorspb",
        "@com_github_cockroachdb_logtags//:logtags",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_gogo_protobuf//proto",
        "@com_github_google_btree//:btree",
        "@io_opentelemetry_go_otel//attribute",
    ],
)

gomock(
    name = "mock_kvcoord",
    out = "mocks_generated_test.go",
    interfaces = [
        "Transport",
    ],
    library = ":kvcoord",
    package = "kvcoord",
    self_package = "github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord",
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

# This noop target is a workaround for https://github.com/bazelbuild/bazel-gazelle/issues/1078.
#
# gazelle:resolve go github.com/cockroachdb/cockroach/pkg/kv/kvclient/kvcoord //build/bazelutil:noop

go_test(
    name = "kvcoord_test",
    size = "medium",
    srcs = [
        "batch_test.go",
        "condensable_span_set_test.go",
        "dist_sender_ambiguous_test.go",
        "dist_sender_circuit_breaker_test.go",
        "dist_sender_rangefeed_mock_test.go",
        "dist_sender_rangefeed_test.go",
        "dist_sender_server_test.go",
        "dist_sender_test.go",
        "helpers_test.go",
        "integration_test.go",
        "main_test.go",
        "priority_refresh_test.go",
        "range_iter_test.go",
        "replayed_commit_test.go",
        "replica_slice_test.go",
        "send_test.go",
        "split_test.go",
        "transport_test.go",
        "txn_coord_sender_savepoints_test.go",
        "txn_coord_sender_server_test.go",
        "txn_coord_sender_test.go",
        "txn_correctness_test.go",
        "txn_interceptor_committer_test.go",
        "txn_interceptor_heartbeater_test.go",
        "txn_interceptor_metric_recorder_test.go",
        "txn_interceptor_pipeliner_client_test.go",
        "txn_interceptor_pipeliner_test.go",
        "txn_interceptor_seq_num_allocator_test.go",
        "txn_interceptor_span_refresher_test.go",
        "txn_test.go",
        ":mock_kvcoord",  # keep
    ],
    data = glob(["testdata/**"]),
    embed = [":kvcoord"],
    exec_properties = select({
        "//build/toolchains:is_heavy": {"test.Pool": "large"},
        "//conditions:default": {"test.Pool": "default"},
    }),
    shard_count = 16,
    deps = [
        "//build/bazelutil:noop",
        "//pkg/base",
        "//pkg/config",
        "//pkg/config/zonepb",
        "//pkg/gossip",
        "//pkg/gossip/simulation",
        "//pkg/keys",
        "//pkg/kv",
        "//pkg/kv/kvbase",
        "//pkg/kv/kvclient",
        "//pkg/kv/kvclient/rangecache",
        "//pkg/kv/kvclient/rangecache/rangecachemock",
        "//pkg/kv/kvpb",
        "//pkg/kv/kvpb/kvpbmock",
        "//pkg/kv/kvserver",
        "//pkg/kv/kvserver/closedts",
        "//pkg/kv/kvserver/concurrency",
        "//pkg/kv/kvserver/concurrency/isolation",
        "//pkg/kv/kvserver/concurrency/lock",
        "//pkg/kv/kvserver/kvserverbase",
        "//pkg/kv/kvserver/liveness",
        "//pkg/kv/kvserver/liveness/livenesspb",
        "//pkg/kv/kvserver/tscache",
        "//pkg/kv/kvserver/txnwait",
        "//pkg/multitenant/tenantcapabilities/tenantcapabilitiesauthorizer",
        "//pkg/raft",
        "//pkg/roachpb",
        "//pkg/rpc",
        "//pkg/rpc/nodedialer",
        "//pkg/security/securityassets",
        "//pkg/security/securitytest",
        "//pkg/server",
        "//pkg/settings/cluster",
        "//pkg/sql/catalog/bootstrap",
        "//pkg/sql/catalog/desctestutils",
        "//pkg/sql/pgwire/pgcode",
        "//pkg/sql/pgwire/pgerror",
        "//pkg/storage",
        "//pkg/storage/enginepb",
        "//pkg/testutils",
        "//pkg/testutils/datapathutils",
        "//pkg/testutils/kvclientutils",
        "//pkg/testutils/localtestcluster",
        "//pkg/testutils/serverutils",
        "//pkg/testutils/skip",
        "//pkg/testutils/sqlutils",
        "//pkg/testutils/testcluster",
        "//pkg/util",
        "//pkg/util/admission/admissionpb",
        "//pkg/util/caller",
        "//pkg/util/ctxgroup",
        "//pkg/util/encoding",
        "//pkg/util/grpcutil",
        "//pkg/util/hlc",
        "//pkg/util/leaktest",
        "//pkg/util/log",
        "//pkg/util/metric",
        "//pkg/util/netutil",
        "//pkg/util/pprofutil",
        "//pkg/util/protoutil",
        "//pkg/util/randutil",
        "//pkg/util/retry",
        "//pkg/util/shuffle",
        "//pkg/util/span",
        "//pkg/util/stop",
        "//pkg/util/syncutil",
        "//pkg/util/timeutil",
        "//pkg/util/tracing",
        "//pkg/util/tracing/tracingpb",
        "//pkg/util/uuid",
        "@com_github_cockroachdb_datadriven//:datadriven",
        "@com_github_cockroachdb_errors//:errors",
        "@com_github_cockroachdb_errors//errutil",
        "@com_github_cockroachdb_redact//:redact",
        "@com_github_golang_mock//gomock",
        "@com_github_sasha_s_go_deadlock//:go-deadlock",
        "@com_github_stretchr_testify//assert",
        "@com_github_stretchr_testify//require",
        "@org_golang_google_grpc//:go_default_library",
        "@org_golang_google_grpc//codes",
        "@org_golang_google_grpc//status",
        "@org_golang_x_sync//errgroup",
    ],
)

stringer(
    name = "gen-txnstate-stringer",
    src = "txn_coord_sender.go",
    typ = "txnState",
)

disallowed_imports_test(
    "kvcoord",
    disallowed_list = [
        "//pkg/storage",
    ],
)
